package burubaka.controller.mnt;

import java.util.List;
import java.util.logging.Logger;

import org.slim3.controller.Navigation;

import burubaka.BurubakaConstants;
import burubaka.common.controller.Controller;
import burubaka.model.PreRaceInfo;
import burubaka.service.PreRaceInfoService;

public class PreRaceInfoDownloadController extends Controller {

	private static final Logger log = Logger.getLogger(PreRaceInfoDownloadController.class.getName());
	private PreRaceInfoService preRaceInfoService = new PreRaceInfoService();

	@Override
	public Navigation run() throws Exception {

		StringBuffer sb = new StringBuffer();
		List<PreRaceInfo> list = preRaceInfoService.findAll();
		for (PreRaceInfo preRaceInfo : list) {
			sb.append(preRaceInfo.getRaceDate());
			sb.append(",");
			sb.append(preRaceInfo.getRaceName());
			sb.append(",");
			sb.append(preRaceInfo.getDisplayRaceName());
			sb.append(",");
			sb.append(preRaceInfo.getDistrictClass());
			sb.append(",");
			sb.append(preRaceInfo.getExecFlag());
			sb.append(System.getProperty("line.separator"));
		}

		log.info(sb.toString());

		download("事前登録レース情報.csv", sb.toString().getBytes(BurubakaConstants.ENCODE_SJIS));

		return null;
	}

}
